<template>
	<view class="login">
		<image src="/static/caifa/login.jpg" mode="aspectFill" class="image" />
		<view class="login-text">
			<view class="login-img"></view>
			<view class="text">欢迎登录</view>
		</view>
		<button class="long-radius-btn sumit-btn" @click="getUserProfile">
			微信用户一键登录
		</button>
		<!-- <button class="long-radius-btn sumit-btn" @getphonenumber="onGetPhoneNumber" open-type="getPhoneNumber">微信用户一键登录</button> -->
		<!-- <button class="btnBig marT140" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
			点击获取手机号
		</button> -->
	</view>
</template>

<script>
	// import { Base64 } from "@/uni_modules/js-base64/base64.js";
	// import { login } from "../../http/api.js";
	// import ajax from "../../http/index.js";
	import {
		Base64
	} from "js-base64"
	export default {
		data() {
			return {};
		},
		mounted() {},
		methods: {
			getUserProfile(e) {
				wx.showLoading({
					title: "加载中",
				});
				uni.login({
					success: (res) => {
						var base64Encoded = Base64.encode(`{"code":"${res.code}"}`);
						this.reglogin(base64Encoded)
					},
				});
			},
			async reglogin(base64Encoded) {
				let res = await this.muajax.login({}, {
					header: {
						"content-type": "application/json",
						'tripartiteToken': `100 ${base64Encoded}`,
					}
				});
				if (res.code == '0000') {
					uni.hideLoading();
					this.$store.dispatch('saveData', {
						field: 'user',
						value: res,
						keep: true,
					})
					this.$store.dispatch('saveData', {
						field: 'token',
						value: res.token,
						keep: true,
					})
					this.nextstep()
				}
			},
			// 登录
			nextstep() {
				uni.reLaunch({
					url: "/pages/home-page/home-page",
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.login {
		height: 100vh;
		display: flex;
		flex-direction: column;

		.image {
			width: 100%;
			height: 386rpx;
		}

		.login-text {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-top: -85rpx;
			z-index: 1;

			.login-img {
				background-image: url(~@/static/caifa/logo.png);
				width: 170rpx;
				height: 170rpx;
				background-size: cover;
			}

			.text {
				font-family: Microsoft YaHei;
				font-weight: 400;
				font-size: 35rpx;
				color: #333333;
				margin-top: 12rpx;
			}
		}

		.long-radius-btn {
			width: 90%;
			// line-height: 92rpx;
			text-align: center;
			margin-top: 338rpx;
		}

		.sumit-btn {
			background: rgba(44, 195, 150, 1);
			border-radius: 46rpx;
			color: #fff;
		}
	}
</style>